#!/usr/bin/python
"""
Tests two different framework possibilities to technical analysis.

The current issue is the flexibility of online blocks x time overhead.

- Gets time data
- Calculates EMA using the first offline framework
- Calculates the same using the proposed online framework with a Feeder and Collector
- Compates the two ellapsed times.

"""
import datetime as dt
import system.navalasystem as na
import misc.quoteperiod as qp
import logging
import time
from misc import misc

na.vala.flagMaster = True
na.vala.Startup()

d = na.vala.db.quote_GetData(qp.daily, "BOVESPA_VISTA_PETR4", 
    dt.datetime(2010, 1, 1, 0, 0), dt.datetime(2013, 12, 12))
print "--------------------------------------------------"


from analysis import tdind

try:
    print "Quote data has %d bars" % len(d)
    t = time.time()
    ema = tdind.EMA()
    ema.size = 7
    ema["input"].fieldName = "close"
    ema["input"][0] = d
    print misc.FormatEllapsed(time.time()-t, "Offline")



#    t = time.time()
#    emag = tdind.EMAGemeu()
#    ema.size = 7
#    ema["input"].fieldName = "close"
#    for i in range(0, len(d)):
#        ema["input"][0] = d[i]
#    print misc.FormatEllapsed(time.time()-t, "ONLINE")
    
except:
    logging.exception("EHEHEHEHE NEGO")

    a = raw_input("Press ENTER")

print "--------------------------------------------------"
na.vala.Cleanup()
